<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./js/velocity.min.js"></script>
  <script src="../vue.js"></script>
</head>

<body>
  <div id="app">
    <!-- // 双向数据绑定 -->
    <input type="text" placeholder="请输入要查找的内容：" v-model="query">
    <!-- // v-bind指令绑定了query和items变量，用来动态传递props -->
    <fade :query="query" :items="items">
      <!-- // fade为自定义组件的名称 -->
      <li v-for="(item, index) in ComputedList" :key="item.msg" :data-index="index">
        {{item.msg}}</li>
    </fade>
  </div>

  <template id="temp">
    <transition-group name="item" tag="ul" @before-enter="beforeEnter" @enter="enter" @leave="leave" :css="false">
      <slot></slot>
    </transition-group>
  </template>

  <script>
    // 注册函数式组件
    Vue.component("fade", {
      functional: true,
      props: ["query", "items"],
      // rander() 渲染函数 接收两个参数 （createElement创建组件模板, context上下文）
      render(createElement, context) {
        return createElement("transition-group", context.children)
      }
    })

    var vm = new Vue({
      el: "#app",
      data: {
        query: "",
        items: [{
            msg: '张三'
          }, {
            msg: '李四'
          }, {
            msg: '张芳芳'
          },
          {
            msg: '王琳琳'
          }, {
            msg: '冯圆'
          }
        ]
      },
      computed: {
        ComputedList() {
          var vm = this.query;
          var nameList = this.items;
          return nameList.filter((item) => {
            return item.msg.toLowerCase().indexOf(vm.toLowerCase()) !== -1;
          })
        }
      }
    })
  </script>
</body>

</html>